package com.shangcheng.server.controller;

import com.shangcheng.model.domain.SmsHomeRecommendProduct;
import com.shangcheng.model.domain.SmsHomeRecommendSubject;
import com.shangcheng.model.vo.PageResult;
import com.shangcheng.model.vo.result.Result;
import com.shangcheng.server.service.SmsHomeRecommendSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author shiqiang
 * @version 1.0
 * @date 2022/5/13 14:13
 */
@RestController
@RequestMapping("/home/recommendSubject")
public class SmsHomeRecommendSubjectController {
    @Autowired
    private SmsHomeRecommendSubjectService homeRecommendSubjectService;
    /**
     * 批量添加首页推荐专题
     * @param homeRecommendSubjecttList 专题集合
     * @return
     */
    @PostMapping("/create")
    public ResponseEntity createSubject(@RequestBody List<SmsHomeRecommendSubject> homeRecommendSubjecttList){
        homeRecommendSubjectService.createSubject(homeRecommendSubjecttList);
        return ResponseEntity.ok(new Result(200,null,"添加成功"));
    }

    /**
     * 批量删除推荐专题
     * @param ids 新品ids
     * @return
     */
    @PostMapping("/delete")
    public ResponseEntity deleteNewPro(Integer[] ids){
        homeRecommendSubjectService.deleteSubject(ids);
        return ResponseEntity.ok(new Result(200,null,"删除成功"));
    }

    /**
     * 分页查询推荐专题
     * @param pageNum
     * @param pageSize
     * @param subjectName
     * @param recommendStatus
     * @return
     */
    @GetMapping("/list")
    public ResponseEntity newProList(@RequestParam(defaultValue = "1") Integer pageNum,
                                     @RequestParam(defaultValue = "10") Integer pageSize,String subjectName,Integer recommendStatus){
        PageResult result=homeRecommendSubjectService.SubjectList(pageNum,pageSize,subjectName,recommendStatus);
        return ResponseEntity.ok(new Result(200,result,null));
    }

    /**
     * 批量修改推荐状态
     * @param ids
     * @param recommendStatus
     * @return
     */
    @PostMapping("/update/recommendStatus")
    public ResponseEntity updateSubjectStatus(Integer[] ids,Integer recommendStatus){
        homeRecommendSubjectService.updateSubjectStatus(ids,recommendStatus);
        return ResponseEntity.ok(new Result(200,null,"修改成功"));
    }

    /**
     * 修改推荐排序
     * @param id
     * @param sort
     * @return
     */
    @PostMapping("/update/sort/{id}")
    public ResponseEntity updateSort(@PathVariable("id") Integer id,@RequestParam Integer sort){
        homeRecommendSubjectService.updateSubjectSort(id,sort);
        return ResponseEntity.ok(new Result(200,null,"修改成功"));
    }
}
